<?php 
include('header.php');
include('menu.php');
include('config.php');
include_once('connection/connection.php');
function getName($colName,$id)
{
	$sqlgetName="select distinct ".$colName."_name from tbl_lookup_location where ".$colName."_id=".$id;
	$querygetName=mysql_query($sqlgetName);
	$rowgetName=mysql_fetch_row($querygetName);
	return $rowgetName[0];
}

if(isset($_POST['submit']))
{
$district=$_POST['district'];
$block=$_POST['block'];
$station=$_POST['station'];
$station_lat=$_POST['lat'];
$station_long=$_POST['long'];
//$catchment=$_POST['catchment'];
$first_year=$_POST['first_year'];
$second_year=$_POST['second_year'];
$query="insert into tbl_dtls_rainfall(district_id,block_id,Station,Station_Latitude,Station_Longitude,year_from,year_to) values('$district','$block','$station','$station_lat','$station_long','$first_year','$second_year')";
$resultSet=mysql_query($query);

$num_row=$_POST['num_row'];

for($i=0; $i<=$num_row; $i++)
		{
			$period='period'.$i;
			$Day='Day'.$i;
			$Month='Month'.$i;
			$rainfall='rainfall'.$i;
			$raindays='raindays'.$i;
			$Hrain='Hrain'.$i;
			//$testing_date='testing_date'.$i;
			
			$period=$_POST[$period];
			$Day=$_POST[$Day];
			$Month=$_POST[$Month];
			$rainfall=$_POST[$rainfall];
			$raindays=$_POST[$raindays];
			$Hrain=$_POST[$Hrain];
			$testing_date=$Day."-".$Month."-".$period;
			//$testing_date=$_POST[$testing_date];
			
			$q5="INSERT INTO tbl_dtls_rainfall_details(district_id,block_id,year,Annual_Rainfall,Annual_Rainydays,Heighest_Rainfall,On_Date) VALUES ('$district','$block','$period','$rainfall','$raindays','$Hrain','$testing_date')";
			$r5=mysql_query($q5);	
		    }	

}

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>P&T</title>
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="js/validate.js"></script>
<script language="Javascript" type="text/javascript" src="water_rainfall_js.js"></script>
<script language="javascript" type="text/javascript">
function validate()
{
	
	if (document.view_main_q1.district.selectedIndex == 0)
    {
        alert ( "Please select District name" );
		document.view_main_q1.district.focus();
           return false;
    }
	if (document.view_main_q1.block.selectedIndex == 0)
    {
        alert ( "Please select Block name" );
		document.view_main_q1.block.focus();
          return false;
    }
	if (document.view_main_q1.station.value == "")
    {
        alert ( "Please enter station name" );
		document.view_main_q1.station.focus();
          return false;
    }
	if (document.view_main_q1.lat2.value < 23 || document.view_main_q1.lat2.value > 31)
    {
        alert ( "Please enter degree of range(23-31) in latitude" );
		document.view_main_q1.lat2.focus();
          return false;
    }
	if (document.view_main_q1.lat22.value == "")
    {
        alert ( "Please enter minute in latitude" );
		document.view_main_q1.lat22.focus();
          return false;
    }
	if (document.view_main_q1.lat22.value > 60)
    {
        alert ( "Please enter less than 60 minute in latitude" );
		document.view_main_q1.lat22.focus();
          return false;
    }
	if (document.view_main_q1.lat23.value == "")
    {
        alert ( "Please enter second in latitude" );
		document.view_main_q1.lat23.focus();
          return false;
    }
	if (document.view_main_q1.lat23.value > 60)
    {
        alert ( "Please enter less than 60 second in latitude" );
		document.view_main_q1.lat23.focus();
          return false;
    }
	if (document.view_main_q1.lat24.value == "")
    {
        alert ( "Please enter degree in longitude" );
		document.view_main_q1.lat24.focus();
          return false;
    }
	if (document.view_main_q1.lat24.value < 69 || document.view_main_q1.lat24.value > 79)
    {
        alert ( "Please enter degree of range(69-79) in longitude" );
		document.view_main_q1.lat24.focus();
          return false;
    }
	
	if (document.view_main_q1.lat25.value == "")
    {
        alert ( "Please enter minute in longitude" );
		document.view_main_q1.lat25.focus();
          return false;
    }
	if (document.view_main_q1.lat25.value > 90)
    {
        alert ( "Please enter less than 90 minute in longitude" );
		document.view_main_q1.lat25.focus();
          return false;
    }
	if (document.view_main_q1.lat26.value == "")
    {
        alert ( "Please enter second in longitude" );
		document.view_main_q1.lat26.focus();
          return false;
    }
	if (document.view_main_q1.lat26.value > 90)
    {
        alert ( "Please enter less than 90 second in longitude" );
		document.view_main_q1.lat26.focus();
          return false;
    }
	if (document.view_main_q1.lat.value == "")
    {
        alert ( "Please click button to convert lat-long in decimal formate" );
		//document.view_main_q1.lat.focus();
          return false;
    }
	if (document.view_main_q1.first_year.selectedIndex == 0)
    {
        alert ( "Please select year range" );
		document.view_main_q1.first_year.focus();
           return false;
    }
	if (document.view_main_q1.second_year.selectedIndex == 0)
    {
        alert ( "Please select year range" );
		document.view_main_q1.second_year.focus();
           return false;
    }
	
	var num_row=document.view_main_q1.num_row.value;
	num_row=parseInt(num_row)+1;
	//alert(num_row);
	//return false;
	for (i=0;i<=num_row;i++)
         {
		   if(document.getElementById('rainfall'+i).value=="")
				{
                  alert ( "Please enter rainfall data" );
		          document.getElementById('rainfall'+i).focus();
                  return false;
		        }
			if(document.getElementById('raindays'+i).value=="")
				{
                  alert ( "Please enter raindays data" );
		          document.getElementById('raindays'+i).focus();
                  return false;
		        }
		   if(document.getElementById('Hrain'+i).value=="")
				{
                  alert ( "Please enter highest rain data" );
		          document.getElementById('Hrain'+i).focus();
                  return false;
		        }
			 if(document.getElementById('Day'+i).value== 0)
				{
                  alert ( "Please select Day" );
		          document.getElementById('Day'+i).focus();
                  return false;
		        }
			if(document.getElementById('Month'+i).value== 0)
				{
                  alert ( "Please select Month" );
		          document.getElementById('Month'+i).focus();
                  return false;
		        }
         }
	
}	
</script>
<script type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" src="js/cal2.js">
/*
Xin's Popup calendar script-  Xin Yang (http://www.yxscripts.com/)
Script featured on/available at http://www.dynamicdrive.com/
This notice must stay intact for use
*/
</script>
<script language="javascript" type="text/javascript">

function showID()
{
//Define calendar(s): addCalendar ("Unique Calendar Name", "Window title", "Form element's name", Form name")
var num=document.getElementById("numfield").value;
var i=0;
for (i=0;i<=num;i++)
{
addCalendar("Calendar" + i, "Select Date", "testing_date" + i, "view_main_q1");
}
// default settings for English
// Uncomment desired lines and modify its values
// setFont("verdana", 9);
 setWidth(90, 1, 15, 1);
// setColor("#cccccc", "#cccccc", "#ffffff", "#ffffff", "#333333", "#cccccc", "#333333");
// setFontColor("#333333", "#333333", "#333333", "#ffffff", "#333333");
// setFormat("yyyy/mm/dd");
// setSize(200, 200, -200, 16);

// setWeekDay(0);
// setMonthNames("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
// setDayNames("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
// setLinkNames("[Close]", "[Clear]");
}
</script>
<script language="javascript" type="text/javascript">
 function ucase(a)
       {
       var b=a.value;
       b=b.toUpperCase();
       a.value=b;
       }

</script>
</head>
<body>
<div align="center">
<form action="" method="post" enctype="multipart/form-data" onSubmit="return validate();" name="view_main_q1" id="view_main_q1">
<table border="0" width="747" id="table1" cellspacing="0" cellpadding="0" style="padding:10px;">
	<tr bgcolor="#C5D8EB">
		<td width="1075" height="29" colspan="4" align="left" valign="top">&nbsp;</td>
	</tr>
	<tr>
	<td bgcolor="#E5E5E5" align="center" colspan="4" style="padding-top:5px">
	<span lang="en-us">&nbsp;</span><span lang="en-us" style="font-size: 8.5pt"><font face="Verdana" color="#006699"><b>Rainfall Data</b></font></span></td>
</tr>
<tr><td bgcolor="#E5E5E5" align="left" colspan="4">&nbsp;</td>
</tr>
<tr><td align="left" colspan="4">&nbsp;</td>
</tr>
		
		<tr>
			<td colspan="4">
			<table width="710" border="0">
              <tr>
                <td width="200"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;District</font></td>
                <td colspan="5">
				<?php
			 	 $query="select DISTINCT district_id from tbl_lookup_location";
		         $result=mysql_query($query);
				 			                                
                   while(list($id)=mysql_fetch_array($result))
		                                         {
                                                    $dist_name[$id]=getName('district',$id);
                                                 }
		  asort($dist_name);
		  echo "<select name='district' id='district' class='txt' onChange=\"changeForm('form_id',this.value)\">\n";
          echo "<option value='0'>==== District ====</option>\n";
		    foreach($dist_name as $key=>$val)
			{
			echo "<option value=\"$key\">".$val."</option> \n" ;
			}
           
		  echo "</select>";
		       ?>		  </td>
              </tr>
              <tr>
                <td><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Block</font></td>
                <td colspan="5"><font id="form_id">
		  	<select name="block" id="block" class="txt">
				<option value="0">=====Block=====</option>
       	  </select></font><span id="formLoader"></span></td>
              </tr>
              <tr>
                <td><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Enter Station</font></td>
                <td colspan="5"><input type="text" name="station" id="station" size="30" onKeyUp="ucase(this);"></td>
              </tr>
              <tr>
                <td rowspan="4" valign="top">
                  <table width="200" border="0">
                    <tr>
                      <td height="28"><font face="Verdana" style="font-size: 8.5pt" color="#000000">Location</font><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;</font></td>
                    </tr>
                    <tr>
                      <td><font face="Verdana" style="font-size: 8.5pt" color="#000000">Station Latitude</font><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;</font></td>
                    </tr>
                    <tr>
                      <td><font face="Verdana" style="font-size: 8.5pt" color="#000000">Station Longitude</font></td>
                    </tr>
                  </table></td>
                <td colspan="3" rowspan="4"><table width="200" height="95" border="1">
                  <tr>
                    <td width="46" align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">Degree</font></td>
                    <td width="46" align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">Min</font></td>
                    <td width="45" align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">Sec</font></td>
                    <td width="35" align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">Zone</font></td>
                  </tr>
                  <tr>
                    <td><input type="text" name="lat2" id="lat2" value="" size="2"></td>
                    <td><input type="text" name="lat22" id="lat22" value="" size="2"></td>
                    <td><input type="text" name="lat23"  id="lat23" value="" size="2"></td>
                    <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;N</font></td>
                  </tr>
                  <tr>
                    <td><input type="text" name="lat24" id="lat24" value="" size="2"></td>
                    <td><input type="text" name="lat25" id="lat25" value="" size="2"></td>
                    <td><input type="text" name="lat26" id="lat26" value="" size="2"></td>
                    <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;E</font></td>
                  </tr>
                </table></td>
                <td>&nbsp;</td>
                <td rowspan="4">
				<span id="conVal">
				<table width="194" border="1">
                  <tr>
                    <td width="144" align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Degree decimal</font> </td>
                    <td width="34" align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Zone</font></td>
                  </tr>
                  <tr>
                    <td>
					<input type="text" name="lat" id="lat" value="" readonly="readonly"></td>
                    <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;N</font></td>
                  </tr>
                  <tr>
                    <td><input type="text" name="long" id="long" value="" readonly="readonly"></td>
                    <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;E</font></td>
                  </tr>
                </table>
				</span>
				</td>
              </tr>
              <tr>
                <td><span id="convert_loader"></span></td>
              </tr>
              <tr>
                <td><img src="images/arrow1.jpg" onClick="convert('con');" style="cursor:pointer;"></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
              
              <tr>
                <td><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Year Range</font></td>
                <td width="68">
				<select name="first_year" id="first_year">
				<option value="0">==Year==</option>
				<?php
				
				$current_year=date("Y");
				for($year=1990;$year<=$current_year;$year++)
				{
				?>
				<option value="<?php echo $year;?>"><?php echo $year;?></option>
				<?php
				}
				?>
				</select></td>
                <td width="21"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;To</font></td>
                <td width="103"><select name="second_year" id="second_year" onChange="rainfall('rain',this.value);">
                  <option value="0">==Year==</option>
                  <?php
				
				$current_year=date("Y");
				for($year=1990;$year<=$current_year;$year++)
				{
				?>
                  <option value="<?php echo $year;?>"><?php echo $year;?></option>
                  <?php
				}
				?>
                </select></td>
                <td width="19">&nbsp;</td>
                <td width="273">&nbsp;</td>
              </tr>
              <tr>
                <td colspan="6" align="left">
				<div id="rain_loader"></div>
				<div style="background-color:#EFEFEF" id="rain"></div></td>
              </tr>
            </table></td>
		</tr>
		<tr>
			<td colspan="4">&nbsp;</td>
		</tr>
		
		<tr>
			<td colspan="4">
			<p align="center">
			<input type="submit" value="submit" name="submit" style="font-size: 8pt; font-family: Verdana; border-style: solid; border-width: 1px; font-weight:bold; background:#666666; color:#FFFFFF; width:140px; height:30px" onClick="view_validate()">&nbsp;</p>			</td>
		</tr>
	</table>
</form>

</div>
</body>
</html>
